import struct

PROTOCOL_VERSION = "0.1"
#包头定义
class pro_message_header(object):
    def __init__(self,seq=0,mlen=0,sys=0,comp=0):
        self.stx = 0XF2 # 帧头
        self.seq =seq  # 序列号
        self.mlen =mlen  #包长
        self.sys =sys  #发送者编号
        self.comp =comp  #发送给飞控或组件（目前组件只有摄像头）0or1

    def header_pack(self):
        return struct.pack('<BBBBB',self.stx,self.seq,self.mlen,self.sys,self.comp)

#包定义及生成
class pro_message(object):
    def __init__(self):
        self.payload =None


    def _pack(self,payload):
        plen = len(payload)
        self.payload = payload[:plen]
        self.header = pro_message_header(mlen=len(self.payload),comp=1)
        self.msg_buffer = self.header.header_pack()+self.payload
        return  self.msg_buffer


